'-------------------------------------------------------------------------------- ' An 'ExeData' is a chunk of data at the end of an executable, it can be added ' at runtime. Its structure is: [CHUNK OF DATA][CHUNK SIZE][CHUNK DESC][MAGIC] ' where: ' - CHUNK OF DATA is any blob of data, text or binary ' - CHUNK SIZE is the hexadecimal length (on 8 bytes) of this blob of data ' - CHUNK DESC is a descriptor (on 3 bytes) of this blob of data, it can be ' anything such as: JPG, CFG, TXT, WAV etc. ' - MAGIC is the ExeData magic value: "{ExDt}" '-------------------------------------------------------------------------------- '-------------------------------------------------------------------------------- TYPE ExeData address AS DWORD length AS DWORD desc AS ASCIIZ * 4 END TYPE '-------------------------------------------------------------------------------- $EXEDATA_MAGIC = "{ExDt}" '-------------------------------------------------------------------------------- GLOBAL sharedData() AS STRING ' when packaging a custom widget '-------------------------------------------------------------------------------- '-------------------------------------------------------------------------------- SUB ParseExeData(BYVAL file AS STRING, BYREF ExDt() AS ExeData) ' Parse an executable and fill the info of its ExeData() parts LOCAL a AS STRING LOCAL i, n AS LONG IF NOT Exist(file) THEN EXIT SUB ELSE a = GetFile(file) ' LogMe "" END SUB '-------------------------------------------------------------------------------- '-------------------------------------------------------------------------------- FUNCTION ClearExeData(BYVAL file AS STRING) AS STRING ' Return the 'exe' part of an executable, w/o any of its ExeData LOCAL a AS STRING LOCAL ln AS DWORD IF NOT Exist(file) THEN EXIT FUNCTION ELSE a = GetFile(file) ' LogMe "" END FUNCTION '-------------------------------------------------------------------------------- '-------------------------------------------------------------------------------- FUNCTION FindExeData(BYVAL desc AS STRING, BYREF ExDt() AS ExeData, _ OPTIONAL BYVAL start AS LONG) AS LONG ' Return the ExeData() index containing descriptor 'desc' ; or 0 if not found LOCAL st, i AS LONG IF start > 1 THEN st = start ELSE st = 1 FUNCTION = 0 FOR i = st TO UBOUND(ExDt) IF TRIM$(UCASE$(ExDt(i).desc)) = TRIM$(UCASE$(desc)) THEN FUNCTION = i EXIT FUNCTION END IF NEXT END FUNCTION '-------------------------------------------------------------------------------- '-------------------------------------------------------------------------------- FUNCTION GetExeData(BYVAL file AS STRING, BYREF ExDtElt AS ExeData) AS STRING ' Return the ExeData(i) part (data chunk) from the executable 'file' LOCAL a AS STRING IF NOT Exist(file) THEN EXIT FUNCTION ELSE a = GetFile(file) IF ExDtElt.address + ExDtElt.length > LEN(a) THEN EXIT FUNCTION ' out-of-bound FUNCTION = MID$(a, ExDtElt.address, ExDtElt.length) END FUNCTION '-------------------------------------------------------------------------------- '-------------------------------------------------------------------------------- FUNCTION AddExeData(src AS STRING, desc AS STRING, chunk AS STRING) AS STRING ' Add 'chunk' data of type 'desc' to the exe (or data) 'src' and return the result LOCAL a, d AS STRING IF LEN(src) < %MAX_PATH AND MID$(src, 2, 2) = ":\" THEN IF NOT Exist(src) THEN EXIT FUNCTION ELSE a = GetFile(src) ' LogMe " 3 THEN ' empty chunk or illegal descriptor FUNCTION = a ' LogMe "Failed. Original file unchanged>" EXIT FUNCTION END IF a += chunk a += HEX$(LEN(chunk),8) a += SPACE$(3-LEN(TRIM$(desc))) + TRIM$(desc) a += $EXEDATA_MAGIC FUNCTION = a ' LogMe "Done. New file is "+FORMAT$(LEN(a),"#,")+" Bytes>" END FUNCTION '-------------------------------------------------------------------------------- '-------------------------------------------------------------------------------- SUB SetFile(dat AS STRING, file AS STRING) LOCAL ff AS LONG KILL file ff = FREEFILE OPEN file FOR BINARY ACCESS WRITE LOCK READ AS #ff PUT$ #ff, dat CLOSE #ff END SUB '-------------------------------------------------------------------------------- '-------------------------------------------------------------------------------- FUNCTION GetFile(file AS STRING) AS STRING LOCAL ff AS LONG LOCAL aa AS STRING IF NOT Exist(file) THEN EXIT FUNCTION ff = FREEFILE OPEN file FOR BINARY ACCESS READ LOCK WRITE AS #ff GET$ #ff, LOF(#ff), aa CLOSE #ff FUNCTION = aa END FUNCTION '--------------------------------------------------------------------------------